package com.iot08.admin.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @version 1.0
 * @Description: 文件上传服务器
 * @time: 2020/8/28 15:21
 * @author: Rock
 */
public class FileUtil {

    /**
     * @param [file, dir, fileName]
     * @time: 2020/8/28 15:31
     * @author: Rock
     * @version 1.0
     */
    public static void upload(MultipartFile file, String dir, String fileName) {
        if (file != null && !file.isEmpty()) {
            try {
                BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(
                        new File(dir + File.separator + fileName)));
                out.write(file.getBytes());
                out.flush();
            } catch (IOException e) {

                e.printStackTrace();
            }
        }
    }
}
